/*
 * Copyright 2009 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.core.ext.js;

import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.dev.PermutationResult;
import com.google.gwt.dev.jjs.ast.JMethod;
import com.google.gwt.dev.jjs.ast.JProgram;

import java.io.Serializable;
import java.util.List;

/**
 * A JavaScript AST. Must be serializable.
 */
public abstract class JavaScriptAst implements Serializable {

  /**
   * Generates the final output script.
   * 
   * @param logger a logger to log to
   * @param javaAst the Java program
   * @return the permutation result
   * @throws InterruptedException if this thread was interrupted
   */
  public abstract PermutationResult generateScript(TreeLogger logger,
      JProgram javaAst) throws InterruptedException;

  /**
   * Returns the list of all Java references found in the external scripts.
   */
  public abstract List<JavaRef> getExternalJavaRefs();

  // Set<JsDefine> getReferencedCompileTimeConstants();

  // void specialize(Set<JsDefine> resolvedCompileTimeConstants);

  /**
   * Parses a JSNI method's JavaScript and returns a handle to the resulting
   * function. The returned function is part of this AST.
   * 
   * @param context the context in which to parse
   * @param js the JavaScript code representing this method
   * @return the JSNI function
   * @throws IllegalArgumentException if the passed-in JavaScript cannot be
   *           parsed
   * @throws IllegalStateException if any existing JsniFunction in this AST has
   *           the same name as the function being parsed
   */
  public abstract JsniFunction parseJsniFunction(
      JsniFunctionParseContext context, JMethod method, String js)
      throws IllegalArgumentException, IllegalStateException;
}
